Add bias keyword argument to cov - #691
Closed
betatim wants to merge 2 commits into
Closed
Conversation
4 tasks
Contributor
Contributor
|
Maybe you can review my PR instead:) |
Member
Author
|
I hadn't seen your PR :D I'll take a look |
bruAristimunha
added a commit
to bruAristimunha/array-api-extra
that referenced
this pull request
Apr 20, 2026
Member
Author
|
Closing for #690 |
lucascolley
pushed a commit
to bruAristimunha/array-api-extra
that referenced
this pull request
Jul 26, 2026
lucascolley
pushed a commit
to bruAristimunha/array-api-extra
that referenced
this pull request
Aug 12, 2026
lucascolley
pushed a commit
to bruAristimunha/array-api-extra
that referenced
this pull request
Aug 12, 2026
lucascolley
added a commit
that referenced
this pull request
Aug 12, 2026
* ENH: expose correction and weights parameters in cov Resolves #688. Adds `axis`, `correction`, `frequency_weights`, and `weights` to `cov`, giving users control over the degrees-of-freedom correction and the observation-axis / weighted variants that `numpy.cov` and `torch.cov` already support. Naming follows array-api conventions (`axis`, `correction`) rather than numpy's (`rowvar`, `bias`, `ddof`); the docstring includes a one-to-one mapping. The delegation moves observations to the last axis via `xp.moveaxis`, collapsing `rowvar` out of the backend dispatch — only `ddof` vs `correction` differs between branches. Dask's native `cov` forces `.compute()` on a lazy scalar when any weights are given, so weighted dask inputs fall through to the generic implementation, which is fully lazy. * MNT: drop device= in cov weights * STY: formatter * TST: add bias tests from #691 * Update _funcs.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update _delegation.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * MNT: rename weights params to fweights/aweights * ENH: validate weights shape in cov * MNT: address lucascolley review * MNT: move weights validation to generic cov * Update _funcs.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * DOC: explain non-integer correction use cases in cov Addresses review feedback (kgryte, betatim) that the motivation for allowing non-integer correction was not obvious from the docstring: weighted unbiased correction and autocorrelated data both require fractional values. * TST: cover weight validation error paths in cov Adds tests for the 1-D shape and length checks in the generic cov path. Raises the diff coverage for this PR from 93.33% to 100%. * Preserve torch autograd in the batched cov path The generic `cov` implementation called `xp.asarray(m)` on its input. For torch this detaches gradients and mutates the caller's tensor in place, so `cov` on a batched tensor (ndim > 2, which routes to the generic path) with `requires_grad=True` returned a detached result and silently zeroed the input's grad. The call is unnecessary: the delegation layer already guarantees `m` is an array (it calls `array_namespace(m)` and reads `m.ndim`). Drop it, and add a torch autograd regression test. * MNT: address cov review feedback * TYP: clarify array cast in cov warning test * lint * Apply suggestions from code review Co-authored-by: Lucas Colley <lucas.colley8@gmail.com> * MNT: address cov review comments - link numpy/torch functions with intersphinx in the cov docstring (torch added to the intersphinx mapping) - add canonical examples for correction, fweights and aweights - explain the int(correction) cast: torch.cov rejects integer-valued floats such as 1.0 at runtime, so typing.cast is not enough - simplify the integer-correction check to float(correction).is_integer() - comment that the NaN shape checks account for Dask reporting unknown dimensions as NaN instead of None --------- Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'd like to use
xpx.covin scikit-learn but we need thebiaskeyword argument.That is all :D